﻿
namespace Mulala.Cavan.Application.MainBoundedContext.AttachmentModule
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Mulala.Cavan.Domain.MainBoundedContext.AttachmentModule;
    using Mulala.Cavan.Domain.MainBoundedContext.SearchModule;
    using Mulala.Cavan.Domain.MainBoundedContext.NannyModule;
    using Mulala.Cavan.Domain.MainBoundedContext.ProprietorModule;
    using Mulala.Cavan.Domain.MainBoundedContext.CorporationModule;
    using Mulala.Cavan.Domain.MainBoundedContext.Setting;

    public class AttachmentAppService : BaseAppService<Attachment, AttachmentSearch, IAttachmentRepository>, IAttachmentAppService
    {
        private IAttachmentGroupRepository AttachmentGroupRepository { get; set; }

        public string GetNannyAvatar(Nanny nanny)
        {
            AttachmentSearch attachmentSearch = AttachmentSearchFactory.CreateAttachmentSearch(AttachmentIdentifier.AttachmentGroup.NannyAvatar, nanny.ID);

            Attachment avatar = this.GetSingleBySearch(attachmentSearch);
            if (null == avatar)
            {
                return Project.Settings.ImageServer + Project.Settings.DefaultAvatarUrl;
            }

            return Project.Settings.ImageServer + avatar.FileUrl + avatar.FileName;
        }

        public Attachment GetNannyAvatar(int id)
        {
            AttachmentSearch attachmentSearch = AttachmentSearchFactory.CreateAttachmentSearch(AttachmentIdentifier.AttachmentGroup.NannyAvatar, id);

            Attachment avatar = this.GetSingleBySearch(attachmentSearch);

            return avatar;
        }

        public string GetProprietorAvatar(Proprietor proprietor)
        {
            AttachmentSearch attachmentSearch = AttachmentSearchFactory.CreateAttachmentSearch(AttachmentIdentifier.AttachmentGroup.ProprietorAvatar, proprietor.ID);

            Attachment avatar = this.GetSingleBySearch(attachmentSearch);
            if (null == avatar)
            {
                return Project.Settings.ImageServer + Project.Settings.DefaultAvatarUrl;
            }

            return Project.Settings.ImageServer + avatar.FileUrl + avatar.FileName;
        }

        public Attachment GetProprietorAvatar(int id)
        {
            AttachmentSearch attachmentSearch = AttachmentSearchFactory.CreateAttachmentSearch(AttachmentIdentifier.AttachmentGroup.ProprietorAvatar, id);

            Attachment avatar = this.GetSingleBySearch(attachmentSearch);

            return avatar;
        }

        public string GetCorporationLogo(Corporation corporation)
        {
            AttachmentSearch attachmentSearch = AttachmentSearchFactory.CreateAttachmentSearch(AttachmentIdentifier.AttachmentGroup.CorporationLogo, corporation.ID);

            Attachment logo = this.GetSingleBySearch(attachmentSearch);
            if (null == logo)
            {
                return Project.Settings.ImageServer + Project.Settings.DefaultLogoUrl;
            }

            return Project.Settings.ImageServer + logo.FileUrl + logo.FileName;
        }

        public Attachment GetCorporationLogo(int id)
        {
            AttachmentSearch attachmentSearch = AttachmentSearchFactory.CreateAttachmentSearch(AttachmentIdentifier.AttachmentGroup.CorporationLogo, id);

            Attachment logo = this.GetSingleBySearch(attachmentSearch);

            return logo;
        }

        public IList<Attachment> GetCorporationPhotos(int id)
        {
            AttachmentSearch attachmentSearch = AttachmentSearchFactory.CreateAttachmentSearch(AttachmentIdentifier.AttachmentGroup.CorporationPhoto, id);

            IList<Attachment> photos = this.GetBySearch(attachmentSearch).ToList();

            return photos;
        }

        public IList<Attachment> GetCorporationCertifications(int id)
        {
            AttachmentSearch attachmentSearch = AttachmentSearchFactory.CreateAttachmentSearch(AttachmentIdentifier.AttachmentGroup.CorporationCertification, id);

            IList<Attachment> photos = this.GetBySearch(attachmentSearch).ToList();

            return photos;
        }

        public AttachmentGroup GetAttachmentGroupByID(int id)
        {
            return this.AttachmentGroupRepository.Get(id);
        }

        public IList<Attachment> GetNannyPhotos(int id)
        {
            AttachmentSearch attachmentSearch = AttachmentSearchFactory.CreateAttachmentSearch(AttachmentIdentifier.AttachmentGroup.NannyPhoto, id);

            IList<Attachment> photos = this.GetBySearch(attachmentSearch).ToList();

            return photos;
        }
    }
}
